<?php

namespace App\Providers;

use Log;
Use Carbon\Carbon;
use DB;
use Laravel\Passport\Events\AccessTokenCreated;
class RevokeOldTokens 
{
    public function __construct()
    {

    }

    public function handle(AccessTokenCreated $event)
    {
        DB::table('oauth_access_tokens')->where('id','!=',$event->tokenId)
        ->where('user_id',$event->userId)
        ->where('client_id',$event->clientId)
        ->where('revoked','=',0)
        ->where('created_at','<',Carbon::now()->toDateTimeString())
        ->delete();
    }
}
